'use strict';

/**
 * @ngdoc overview
 * @name appApp
 * @description
 * # appApp
 *
 * Main module of the application.
 */
angular
  .module('appApp', [
    'ngAnimate',
    'ngAria',
    'ngCookies',
    'ngResource',
    'ngRoute',
    'ngSanitize',
    'ngTouch'
  ])

  .config(function ($routeProvider,$locationProvider) {
    $locationProvider.hashPrefix('');
    $routeProvider
      .when('/', {
        title:'首页',
        templateUrl: 'views/home.html',
        controller: 'HomeCtrl',
        controllerAs: 'home'
      })
      .when('/about', {
        templateUrl: 'views/about.html',
        controller: 'AboutCtrl',
        controllerAs: 'about'
      })
      .when('/home', {
        title:'首页',
        templateUrl: 'views/home.html',
        controller: 'HomeCtrl',
        controllerAs: 'home'
      })
      .when('/introduction/:case_id', {
        title:'中心简介',
        templateUrl: 'views/introduction.html',
        controller: 'IntroductionCtrl',
        controllerAs: 'introduction'
      })
      .when('/doctor-detail/:doc_id', {
        title:'医生详情',
        templateUrl: 'views/doctor-detail.html',
        controller: 'DoctorDetailCtrl',
        controllerAs: 'doctorDetail'
      })
      .when('/jzservice', {
        title:'就诊服务',
        templateUrl: 'views/jzservice.html',
        controller: 'JzserviceCtrl',
        controllerAs: 'jzservice'
      })
      .when('/know-kidneytp', {
        title:'了解肾移植',
        templateUrl: 'views/know-kidneytp.html',
        controller: 'KnowKidneytpCtrl',
        controllerAs: 'knowKidneytp'
      })
      .when('/kidneytp-process', {
        title:'肾移植过程',
        templateUrl: 'views/kidneytp-process.html',
        controller: 'KidneytpProcessCtrl',
        controllerAs: 'kidneytpProcess'
      })
      .when('/kidneytp-question', {
        title:'常见问题',
        templateUrl: 'views/kidneytp-question.html',
        controller: 'KidneytpQuestionCtrl',
        controllerAs: 'kidneytpQuestion'
      })
      .when('/news-center', {
        title:'新闻中心',
        templateUrl: 'views/news-center.html',
        controller: 'NewsCenterCtrl',
        controllerAs: 'newsCenter'
      })
      .when('/appointment', {
        title:'就诊预约',
        templateUrl: 'views/appointment.html',
        controller: 'AppointmentCtrl',
        controllerAs: 'appointment'
      })
      .when('/visit-guide', {
        title:'就诊指南',
        templateUrl: 'views/visit-guide.html',
        controller: 'VisitGuideCtrl',
        controllerAs: 'visitGuide'
      })
      .when('/news-centerdetail/:news_id', {
        title:'新闻详情',
        templateUrl: 'views/news-centerdetail.html',
        controller: 'NewsCenterdetailCtrl',
        controllerAs: 'newsCenterDetail'
      })
      .when('/identity-verify', {
        title:'登录',
        templateUrl: 'views/identity-verify.html',
        controller: 'IdentityVerifyCtrl',
        controllerAs: 'identityVerify'
      })
      .when('/know-ndz', {
        title:'了解尿毒症',
        templateUrl: 'views/know-ndz.html',
        controller: 'KnowNdzCtrl',
        controllerAs: 'knowNdz'
      })
      .when('/kidney-detail/:kidney_id', {
        title:'了解肾移植',
        templateUrl: 'views/kidney-detail.html',
        controller: 'KidneyDetailCtrl',
        controllerAs: 'kidneyDetail'
      })
      .when('/kidney-prodetail/:kidneypro_id', {
        title:'肾移植过程',
        templateUrl: 'views/kidney-prodetail.html',
        controller: 'KidneyProdetailCtrl',
        controllerAs: 'kidneyProdetail'
      })
      .when('/guide-behosp', {
        title:'入院指南',
        templateUrl: 'views/guide-behosp.html',
        controller: 'GuideBehospCtrl',
        controllerAs: 'guideBehosp'
      })
      .when('/guide-leavehosp', {
        title:'出院指南',
        templateUrl: 'views/guide-leavehosp.html',
        controller: 'GuideLeavehospCtrl',
        controllerAs: 'guideLeavehosp'
      })
      .when('/guide-inhosp', {
        title:'院内指导',
        templateUrl: 'views/guide-inhosp.html',
        controller: 'GuideInhospCtrl',
        controllerAs: 'guideInhosp'
      })
      .when('/guide-outhosp', {
        title:'院外指导',
        templateUrl: 'views/guide-outhosp.html',
        controller: 'GuideOuthospCtrl',
        controllerAs: 'guideOuthosp'
      })
      .when('/kidneytp-qesdetail/:kidneyqes_id', {
        title:'常见问题',
        templateUrl: 'views/kidneytp-qesdetail.html',
        controller: 'KidneytpQesdetailCtrl',
        controllerAs: 'kidneytpQesdetail'
      })
      .when('/guide-behospdetail/:behosp_id', {
        title:'入院指南',
        templateUrl: 'views/guide-behospdetail.html',
        controller: 'GuideBehospdetailCtrl',
        controllerAs: 'guideBehospdetail'
      })
      .when('/guide-inhospdetail/:inhosp_id', {
        title:'院内指导',
        templateUrl: 'views/guide-inhospdetail.html',
        controller: 'GuideInhospdetailCtrl',
        controllerAs: 'guideInhospdetail'
      })
      .when('/guide-outhospdetail/:outhosp_id', {
        title:'院外指导',
        templateUrl: 'views/guide-outhospdetail.html',
        controller: 'GuideOuthospdetailCtrl',
        controllerAs: 'guideOuthospdetail'
      })
      .when('/guide-leavehospdetail/:leavehosp_id', {
        title:'出院指南',
        templateUrl: 'views/guide-leavehospdetail.html',
        controller: 'GuideLeavehospdetailCtrl',
        controllerAs: 'guideLeavehospdetail'
      })
      .when('/viable-transplant', {
        title:'活体移植',
        templateUrl: 'views/viable-transplant.html',
        controller: 'ViableTransplantCtrl',
        controllerAs: 'viableTransplant'
      })
      .when('/transplant-prepar', {
        title:'移植准备',
        templateUrl: 'views/transplant-prepar.html',
        controller: 'TransplantPreparCtrl',
        controllerAs: 'transplantPrepar'
      })
      .otherwise({
        redirectTo: '/'
      });
  })

  .run(['$rootScope','$location','cfg','$http','uploadImg', function($rootScope, $location, cfg, $http, uploadImg){
    
    $rootScope.$on('$routeChangeSuccess', function(angularEvent,current,previous){
      var title = current && current.$$route && current.$$route.title;
      if(!title){
        document.title = '曾教授移植网';
      }
      document.title = title;
      var $body = $('body');
      // hack在微信等webview中无法修改document.title的情况
      var $iframe = $("<iframe src='favicon.ico' style='display:none'></iframe>").on('load', function() {
        setTimeout(function() {
          $iframe.off('load').remove()
        }, 0)
      }).appendTo($body)
    });
    $rootScope.fullPath = function(url){
      return cfg.baseImgUrl + url;
    };
    uploadImg.initWxSdk();
  }])
  
  .filter('trustHtml', function ($sce) {
    return function (input) {
      return $sce.trustAsHtml(input);
    };
  });
;
